﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Security;
using SIMCObjetoNegocio;

public partial class Account_Login : System.Web.UI.Page
{



    protected void Page_Load(object sender, EventArgs e)
    {
        //Log.Log.Info(Log.LogOrigen.RRHH, "Mi primer log", "1", "2");
    }

    protected void LoginUser_LoggedIn(object sender, EventArgs e)
    {
        SimcMembershipProvider provider = (SimcMembershipProvider)Membership.Provider;
       
        Session["Usuario"] = provider.Usuario;

        if (((MembershipUsuario)Session["Usuario"]).TieneClaveTemporal)
        {
            TimeSpan tiempoTranscurrido = (DateTime.Now - ((MembershipUsuario)Session["Usuario"]).TempPasswordDate);

            if (tiempoTranscurrido.Hours < Convert.ToInt32(ConfigurationManager.AppSettings["HorasCaducidadPasswordTemporal"].ToString()))
            {
                Session["Variable"] = new SessionVariable();
                Response.Redirect("~/Administracion/CambioContrasenna.aspx");
            }
            else
            {
                lblMensaje.Text = "Contraseña temporal ha caducado";
            }
        }
        else
        {
            if (((MembershipUsuario)Session["Usuario"]) != null)
            {
                Session["Variable"] = new SessionVariable();

                Response.Redirect("~/PrincipalExterno.aspx");
                                   
            }
        }
    }

    protected void LoginUser_LoginError(object sender, EventArgs e)
    {
        try
        {
            LoginUser.FailureText = "El usuario y/o contraseña son inválidos";
        }
        catch (Exception ex)
        {
            LoginUser.FailureText = ex.Message;
        }
    }
    
}
